package com.HW.Search;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.Scanner;

/**
 * @ClassName : TArrayMinNum
 * @Author : kele
 * @Date: 2023/11/5 14:11
 * @Description :
 */
public class TArrayMinNumPlus {

    public static void main(String[] args) {


        Scanner sc = new Scanner(System.in);
        String[] str = sc.nextLine().split(" ");
        handle(str);

    }

    public static void handle(String[] str) {


        ArrayList<String> zero = new ArrayList<>();
        ArrayList<String> noZero = new ArrayList<>();

        for (String s : str) {
            if (s.startsWith("0")) {
                zero.add(s);
            } else {
                noZero.add(s);
            }
        }

        zero.sort((o1, o2) -> (o1 + o2).compareTo(o2 + o1));

        String str_zero = String.join("", zero);

        if (noZero.size() > 0) {

            ArrayList<String> head = new ArrayList<>();

            noZero.sort((o1, o2) -> (o1 + o2).compareTo(o2 + o1));
            char c = noZero.get(0).charAt(0);
            head.add(noZero.remove(0));

            while (noZero.size() > 0 && noZero.get(0).startsWith(c + "")) {
                head.add(noZero.remove(0));
            }

            String res = null;
            for (int i = 0; i < head.size(); i++) {

                ArrayList<String> tail = new ArrayList<>();

                tail.addAll(noZero);
                tail.addAll(head.subList(0, i));
                tail.addAll(head.subList(i + 1, head.size()));

                tail.sort((o1, o2) -> (o1 + o2).compareTo(o2 + o1));

                String t = "";
                for (String s : tail) {
                    t += s;
                }

                String h = head.get(i);


                if (res != null) {
                    String tmp = h + zero + t;
                    if (tmp.compareTo(res) < 0) {
                        res = tmp;
                    }

                } else {
                    res = h + zero + t;
                }
            }
            System.out.println(res);


        } else {
            System.out.println(str_zero.replaceAll("^0+", ""));
        }


        Arrays.sort(str, (o1, o2) -> (o1 + o2).compareTo(o2 + o1));


        if (str[0].startsWith("0")) {
            for (int i = 1; i < str.length; i++) {
                if (!str[i].startsWith("0")) {
                    str[0] = str[i] + str[0];
                    str[i] = "";
                    break;
                }
            }
        }
        String res = "";
        for (String s : str) {
            res += s;
        }

        res = "".equals(res) ? "0" : res;

        System.out.println(res);

    }
}
